//
//  RHStringDataCell.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/10/25.
//

#import "RHStringDataCell.h"
#import "RHStringDataChartView.h"

@interface RHStringDataCell()

@property (nonatomic, strong) RHStringDataChartView *chartView;

@end
@implementation RHStringDataCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self setupUI];
    }
    return self;
}

- (void)setChartModel:(DevChartModel *)chartModel{
    _chartModel = chartModel;

    [_chartView setChartModel:_chartModel];
}


-(void)setupUI
{
    self.contentView.backgroundColor = CFTabViewBgColor;
    UIView *bgView = [[UIView alloc] init];
    [bgView.layer setCornerRadius:8];
    bgView.layer.masksToBounds = YES;
    [bgView setBackgroundColor:UIColor.whiteColor];
    [self.contentView addSubview:bgView];
    
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 15, 0, 15));
    }];
    NSInteger type = 0;
    if ([self.reuseIdentifier containsString:@"Month"]) {
        type = 1;
    }
    if ([self.reuseIdentifier containsString:@"Day"]) {
        type = 2;
    }
    if ([self.reuseIdentifier containsString:@"Year"]) {
        type = 0;
    }
    _chartView = [[RHStringDataChartView alloc] initWithFrame:CGRectMake(5, 5,SCREEN_WIDTH-40, 250+130) type:type];
    [bgView addSubview:_chartView];
    kWeakSelf;
    _chartView.fullChartBlock = ^{
        if (weakSelf.fullChartBlock) {
            weakSelf.fullChartBlock();
        }
    };
    _chartView.selectTopToolBlock = ^(NSInteger index) {
        if (weakSelf.selectTopToolBlock) {
            weakSelf.selectTopToolBlock(index);
        }
    };
    
    _chartView.subTimeBlock = ^{//日期往前
        if (weakSelf.subTimeBlock) {
            weakSelf.subTimeBlock();
        }
    };
    
    _chartView.addTimeBlock = ^{//日期往后
        if (weakSelf.addTimeBlock) {
            weakSelf.addTimeBlock();
        }
    };
    
    _chartView.changeTimeBlock = ^{
        if (weakSelf.changeTimeBlock) {
            weakSelf.changeTimeBlock();
        }
    };
  
    [_chartView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 0, 0, 0));
       
    }];
}

@end
